package com.liwenfeng.diancanspringboot.service.impl;

import com.liwenfeng.diancanspringboot.mapper.EmployeeMapper;
import com.liwenfeng.diancanspringboot.pojo.entity.Employee;
import com.liwenfeng.diancanspringboot.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private EmployeeMapper employeeMapper;

    // 修改店铺状态,admin账号job属性为1时，代表店铺营业，0代表打烊
    // sex属性为1时，代表自动接单状态，0代表手动接单
    @Override
    public String startOrStop(String status) {
        Employee admin = employeeMapper.getByUsername("admin");
        Employee employee = new Employee();
        employee.setId(admin.getId());
        employee.setCreateUser(Long.valueOf(status));
        int update = employeeMapper.update(employee);
        if (update > 0) {
            return status;
        }
        return null;
    }

    // 获取店铺状态
    @Override
    public Integer getStatus() {
        Employee admin = employeeMapper.getByUsername("admin");
        if (admin != null) {
            return Math.toIntExact(admin.getCreateUser());
        }
        return null;
    }
}
